package plantable;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableModel;

public class AttributiveCellRenderer extends JLabel implements
		TableCellRenderer {
	protected static Border noFocusBorder;

	public AttributiveCellRenderer() {
		noFocusBorder = new EmptyBorder(1, 2, 1, 2);
		setOpaque(true);
		setBorder(noFocusBorder);
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {

		Color foreground = null;
		Color background = null;
		Font font = null;
		TableModel model = table.getModel();
		
		
	    //return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

		if (value instanceof String) {

			String[] array = ((String) value).split(";");
			int cut = 0;
			String tooltipvalue = null;
			int lotebackgroundcolor = 220;
			
			if(array.length>2) {
				value = (Object) array[0];
				cut = Integer.valueOf(array[1]);
				if(cut==1)
					tooltipvalue = array[2];
				else if(cut==2)
					lotebackgroundcolor = Integer.valueOf(array[2]);
			}
			
			if(cut == 1) 
				setToolTipText("<html>" + tooltipvalue + "</html>");
			else 
				setToolTipText(tooltipvalue);
			
			this.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
			setVerticalTextPosition(JLabel.TOP);
			//this.setV
			

			if (((String) value).startsWith("<b> Lote</b>")) {
				
			
				setBorder(new SoftBevelBorder(SoftBevelBorder.RAISED));
				setBackground(new Color(lotebackgroundcolor, lotebackgroundcolor, 220));
				setForeground(new Color(0, 0, 0));

				value = "<html> " + value;
				
			} else if (((String) value).startsWith("<b> Dispensar")) {
				
				//setBackground(new Color(216, 191, 216));
				setBackground(new Color(231, 158, 169));
				//E79EA9
				setForeground(new Color(0, 0, 0));
				
				value = "<html> " + value + "<p> &nbsp;";
				
			} else if (((String) value).startsWith("<b> Produccion")) {
				
				setBackground(new Color(135, 206, 250));
				setForeground(new Color(0, 0, 0));

				value = "<html> " + value;
				
			} else if (((String) value).startsWith("<b> Llenado")) {
				
				setBackground(new Color(143, 188, 143));
				setForeground(new Color(0, 0, 0));

				value = "<html> " + value;

			} else if (((String) value).startsWith("<b> Loteado")) {
				
				//setBackground(new Color(238, 232, 170));
				setBackground(new Color(238, 203, 173));
				setForeground(new Color(0, 0, 0));
				
				value = "<html> " + value;

			} else if (((String) value).startsWith("<b> Etiquetado")) {
				
				setBackground(new Color(238, 232, 170));
				setForeground(new Color(0, 0, 0));
				
				value = "<html> " + value + "<p> &nbsp;";
				
			} else if (((String) value).startsWith("<b> Bandas")) {
				
				setBackground(new Color(255, 225, 255));
				setForeground(new Color(0, 0, 0));
				
				value = "<html> " + value + "<p> &nbsp;";
				
			} else if (((String) value).startsWith("<b> Empaque")) {
				
				//setBackground(new Color(176, 196, 222));
				setBackground(new Color(140, 140, 255));
				setForeground(new Color(0, 0, 0));

				value = "<html>  " + value + "<p> &nbsp;";
				
			} else if (((String) value).startsWith("<b> FIN")) {
				
				setBackground(new Color(97, 0, 0));
				setForeground(new Color(230, 230, 230));

				value = "<html> " + value;
				
			} else if (((String) value).startsWith("<b> Tiempo Muerto")) {
				
				setBackground(new Color(136, 136, 136));
				setForeground(new Color(230, 230, 230));
				
				value = "<html> " + value;
				
			} else if (((String) value).startsWith("<b> Hora Almuerzo")) {
				
				
				setBackground(new Color(198, 142, 23));
				setForeground(new Color(230, 230, 230));
				
				value = "<html> " + value;
				
			}
		}

	
		setFont((font != null) ? font : table.getFont());

		setValue(value);
		return this;
	}

	protected void setValue(Object value) {
		setText((value == null) ? "" : value.toString());
	}
}
